﻿#region [ License information          ]
/* ************************************************************
 *
 * Copyright (c) Bjørn Bouet Smith, 2010, 2011
 *
 * This source code is subject to terms and conditions of 
 * Microsoft Public License (Ms-PL).
 * 
 * A copy of the license can be found in the license.txt
 * file at the root of this distribution. If you can not 
 * locate the License, please send an email to bjornsmith@gmail.com
 * 
 * By using this source code in any fashion, you are 
 * agreeing to be bound by the terms of the Microsoft 
 * Permissive License.
 *
 * You must not remove this notice, or any other, from this
 * software.
 *
 * ************************************************************/
#endregion

using System;

namespace Smith.AMC
{
    /// <summary>
    /// Implementation of the ICacheItem.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class CacheItem<T> : ICacheItem<T>
    {
        /// <summary>
        /// Gets or sets the cas value.
        /// the CAS value is to be used if an item is retrieved from the cache, modified
        /// and then added to the cache again.
        /// </summary>
        /// <value></value>
        public ulong CASValue
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the cache key, by which the item is identified in the cache
        /// </summary>
        /// <value></value>
        public string CacheKey
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public T Value
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        object ICacheItem.Value
        {
            get
            {
                return Value;
            }

            set
            {
                Value = (T)value;
            }
        }

        /// <summary>
        /// Gets or sets the life time of the item in the cache.
        /// This property should be set when adding items to the cache.
        /// </summary>
        /// <value></value>
        public TimeSpan LifeTime
        {
            get;
            set;
        }
    }
}
